package com.rstrulak.constant;

import org.apache.commons.lang.builder.ToStringBuilder;
public class PageInfo {
    /**
     * Requested page size.
     */
    private int pageSize;
    /**
     * The number of requested page (starting from 0).
     */
    private int pageNo = 0;

    /**
     * Resulting pages count.
     */
    private int pagesCount;
    /**
     * Total results count.
     */
    private int resultsCount;

    /**
     * Basic constructor assuming that the page fetched is the first page.
     * 
     * @param pageSize - requested page size
     */
    public PageInfo(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * Full request constructor.
     * 
     * @param pageSize - requested page size
     * @param pageNo - page number to fetch
     */
    public PageInfo(int pageSize, int pageNo) {
        this.pageSize = pageSize;
        this.pageNo = pageNo;
    }

    /**
     * Getter for pageSize.
     * 
     * @return the pageSize
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * Getter for pageNo.
     * 
     * @return the pageNo
     */
    public int getPageNo() {
        return pageNo;
    }

    /**
     * Getter for pagesCount.
     * 
     * @return the pagesCount
     */
    public int getPagesCount() {
        return pagesCount;
    }

    /**
     * Getter for resultsCount.
     * 
     * @return the resultsCount
     */
    public int getResultsCount() {
        return resultsCount;
    }

    /**
     * Setter for pageSize.
     * 
     * @param pageSize the pageSize to set
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * Setter for pageNo.
     * 
     * @param pageNo the pageNo to set
     */
    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    /**
     * Setter for pagesCount.
     * 
     * @param pagesCount the pagesCount to set
     */
    public void setPagesCount(int pagesCount) {
        this.pagesCount = pagesCount;
    }

    /**
     * Apart from setting the results count it also calculates pages count.
     * 
     * @param resultsCount - total results count
     */
    public void setResultsCount(int resultsCount) {
        this.resultsCount = resultsCount;
        this.pagesCount = resultsCount / pageSize;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this).append("pageSize", pageSize).append("pageNo", pageNo).append("pagesCount", pagesCount).append("resultsCount",
                resultsCount).toString();
    }
}
